
package it.allerj.analysis;

import blobDetection.BlobDetection;
import java.awt.image.BufferedImage;
import java.util.Iterator;
import java.util.concurrent.ConcurrentSkipListSet;

/**
 * @author masci
 * 
 * We expect black reference points to be
 * on upper-left and upper-right corners
 * of the membrane, like this:
 * 
 * O - - - O
 * - - - - -
 * - - - - -
 * - - - - -
 * - - - - -
 */
class RefPointDetector extends Detector {
      
    public RefPointDetector(BufferedImage img, BlobFilter blobFilter) {
        super(img, blobFilter);
    }    
    
    protected boolean checkBlobDetection(BlobDetection bd) {
        
        if (bd.getBlobNb() < 2) {
            return false;
        }
        
        // retrieve blobs info for two biggest references
        ConcurrentSkipListSet refmarks = new ConcurrentSkipListSet();
        for (int i=0; i<bd.getBlobNb(); ++i) {
            DotMark d = new DotMark(bd.getBlob(i), image_w, image_h);
            refmarks.add(d);            
        }
        
        Iterator<DotMark> it = refmarks.descendingIterator();
        dotMarksFound.add(it.next());
        dotMarksFound.add(it.next());
        return true;
    }

}
